import vue from 'vue'
import vueRouter from 'vue-router'
vue.use(vueRouter)
const router = new vueRouter({
    mode:'hash',
    routes:[
        {
            path:"/login",
            component:()=>import('../views/login.vue'),
        },
        {
            path:"/home",
            name:'home',
            redirect:'/users',
            component:()=>import('../views/homepag.vue'),
            children:[
                {
                    path:"/users",
                    component:()=>import('../views/home/userlist.vue'),
                },
                {
                    path:"/roles",
                    component:()=>import('../views/home/roles.vue'),
                  
                },
                {
                    path:"/rights",
                    component:()=>import('../views/home/rights.vue'),
                  
                },
                {
                    path:"/goods",
                    component:()=>import('../views/home/goods.vue'),
                },
                {
                    path:"/goodsinfo",
                    component:()=>import('../views/home/addgoodsInfo.vue'),
                },
                {
                    path:"/params",
                    component:()=>import('../views/home/params.vue'),
                  
                },
                {
                    path:"/categories",
                    component:()=>import('../views/home/categories.vue'),
                  
                },
                {
                    path:"/orders",
                    component:()=>import('../views/home/orders.vue'),
                  
                },
                {
                    path:"/reports",
                    component:()=>import('../views/home/reports.vue'),
                },  
                {
                    path:"/welcome",
                    component:()=>import('../views/welcome.vue'),
                },
            ]
        },
        {
            path:"/mockDemo",
            component:()=>import('../views/mockDemo.vue'),
        },
      
        {
            path:'/',
            redirect:'/welcome',
        }
    ]
})
router.beforeEach((to,from,next)=>{
    if(to.fullPath!='/login'){
        if(window.sessionStorage.getItem('token')){
            next()
        }else if(!window.sessionStorage.getItem('token')){
            next('/login')
        }
    }else if(to.fullPath=='/login'){
        return next()
    }

})
export default router